/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年2月3日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package iterator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Type ConcreteMyAggregate
 * @Desc
 * @author 52489
 * @date 2019年2月3日
 * @Version V1.0
 */
public class ConcreteMyAggregate {
    private List<Object> list = new ArrayList<>();

    public void addObj(Object object) {
        this.list.add(object);

    }

    public void removeObj(Object object) {
        this.list.remove(object);

    }

    public List<Object> getList() {
        return list;
    }

    public void setList(List<Object> list) {
        this.list = list;
    }

    public MyIterator createIterator() {
        return new ConcreteIterator();
    }

    private class ConcreteIterator implements MyIterator {

        private int cursor;

        /*
         * (non-Javadoc)
         * 
         * @see iterator.MyIterator#first()
         */
        @Override
        public void first() {
            cursor = 0;
        }

        /*
         * (non-Javadoc)
         * 
         * @see iterator.MyIterator#next()
         */
        @Override
        public void next() {
            if (cursor < list.size()) {
                cursor++;
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see iterator.MyIterator#hasNext()
         */
        @Override
        public boolean hasNext() {
            return cursor < list.size() ? true : false;
        }

        /*
         * (non-Javadoc)
         * 
         * @see iterator.MyIterator#getCurrentObj()
         */
        @Override
        public Object getCurrentObj() {
            return list.get(cursor);
        }

    }

    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
    }

}
